package com.tjetc.controller;

import com.tjetc.common.JsonResult;
import com.tjetc.entity.User;
import com.tjetc.service.LikesService;
import com.tjetc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;
    // 注册接口
    @RequestMapping("register")
    public JsonResult register(@RequestParam String username, @RequestParam String password,@RequestParam  String phone) {
       return userService.register(username,password,phone);

    }

    // 登录接口
    @RequestMapping("login")
    public JsonResult login(@RequestParam String username, @RequestParam String password) {
       return  userService.login(username, password);
    }

    // 修改个人信息接口
    @RequestMapping("update")
    public JsonResult updateUserInfo(@RequestBody User user) {
       return userService.updateUserInfo(user);

}// 查询用户信息接口
    @RequestMapping("getById/{id}")
    public JsonResult getUserById(@PathVariable("id") Long userId) {
        return userService.getUserById(userId);
    }

    @RequestMapping("getExp")
    public JsonResult getUserById(@RequestParam String username, @RequestParam long exp) {
        return userService.gainExperience(exp,username);
    }

}
